package com.java2207.group1.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.java2207.group1.pojo.Lunch;
import com.java2207.group1.pojo.Purchase;
import com.java2207.group1.service.PurchaseService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * @author AL 2022/7/27  8:55
 */
@Component
@Scope("prototype")//设置多例模式
public class WebPurchaseListener extends AnalysisEventListener {


    @Autowired
    private PurchaseService purchaseService;

    @Override
    public void invoke(Object data, AnalysisContext analysisContext) {
        Purchase purchase = new Purchase();
        BeanUtils.copyProperties(data,purchase);
        purchaseService.addPurchase(purchase);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
